﻿using EasyERP_BLL.Base;
using EasyERP_BLL;
using EasyERP_Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyERP_View.FrmBase;
using EasyERP_View.FrmWares;

namespace EasyERP_View.POP
{
    /// <summary>
    /// 子代码参照窗体
    /// </summary>
    public partial class FrmPopMinor : Form
    {
        /// <summary>
        /// 子代码实体对象
        /// </summary>
        private readonly B_Minor model = new B_Minor();

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public FrmPopMinor(B_Minor minor)
        {
            InitializeComponent();
            model = minor;
            Text = model.major_cd;      //窗体Text显示主代码
        }
        #endregion

        #region 主代码查询方法
        /// <summary>
        /// 主代码查询方法
        /// </summary>
        private void Query()
        {
            //声明子代码业务逻辑类对象
            B_Minor_BLL Minor_BLL = new B_Minor_BLL();

            //数据封装
            if (string.IsNullOrEmpty(model.minor_cd))
            {
                model.minor_cd = TxtMinor_cd.Text.Trim();
            }
            if (string.IsNullOrEmpty(model.minor_nm))
            {
                model.minor_nm = TxtMinor_nm.Text.Trim();
            }

            DataTable dt = Minor_BLL.Get_B_Minor_Pop(model);
            //绑定DataGridView
            DGView.DataSource = dt;

            //清空子代码实体属性值
            model.minor_cd = "";
            model.minor_nm = "";

            if (dt.Rows.Count == 0)
            {
                B_Message_BLL.MessageCaveat("1004");
            }
        }
        #endregion

        #region 单击查询按钮事件
        /// <summary>
        /// 单击查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            Query();
        }
        #endregion

        #region 窗体加载事件
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmPopMinor_Load(object sender, EventArgs e)
        {
            Query();
        }
        #endregion

        #region 双击单元格任意行事件
        /// <summary>
        /// 双击单元格任意行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DGView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
            {
                FrmItem.minor_cd = DGView[minor_cd.Name, e.RowIndex].Value.ToString();
                FrmItem.minor_nm = DGView[minor_nm.Name, e.RowIndex].Value.ToString();
                Close();
            }
        }
        #endregion
    }
}
